<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/corelib/tools/qpoint.cpp -->
<head>
  <title>Qt 4.3: QPoint Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QPoint Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
<p>The QPoint class defines a point in the plane using integer precision. <a href="#details">More...</a></p>
<pre> #include &lt;QPoint&gt;</pre><ul>
<li><a href="qpoint-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qpoint.html#QPoint">QPoint</a></b> ()</li>
<li><div class="fn"/><b><a href="qpoint.html#QPoint-2">QPoint</a></b> ( int <i>x</i>, int <i>y</i> )</li>
<li><div class="fn"/>bool <b><a href="qpoint.html#isNull">isNull</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qpoint.html#manhattanLength">manhattanLength</a></b> () const</li>
<li><div class="fn"/>int &amp; <b><a href="qpoint.html#rx">rx</a></b> ()</li>
<li><div class="fn"/>int &amp; <b><a href="qpoint.html#ry">ry</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qpoint.html#setX">setX</a></b> ( int <i>x</i> )</li>
<li><div class="fn"/>void <b><a href="qpoint.html#setY">setY</a></b> ( int <i>y</i> )</li>
<li><div class="fn"/>int <b><a href="qpoint.html#x">x</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qpoint.html#y">y</a></b> () const</li>
<li><div class="fn"/>QPoint &amp; <b><a href="qpoint.html#operator-2a-eq">operator*=</a></b> ( qreal <i>factor</i> )</li>
<li><div class="fn"/>QPoint &amp; <b><a href="qpoint.html#operator-2b-eq">operator+=</a></b> ( const QPoint &amp; <i>point</i> )</li>
<li><div class="fn"/>QPoint &amp; <b><a href="qpoint.html#operator--eq">operator-=</a></b> ( const QPoint &amp; <i>point</i> )</li>
<li><div class="fn"/>QPoint &amp; <b><a href="qpoint.html#operator-2f-eq">operator/=</a></b> ( qreal <i>divisor</i> )</li>
</ul>
<a name="related-non-members"></a>
<h3>Related Non-Members</h3>
<ul>
<li><div class="fn"/>bool <b><a href="qpoint.html#operator-not-eq-13">operator!=</a></b> ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator-2a">operator*</a></b> ( const QPoint &amp; <i>point</i>, qreal <i>factor</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator-2a-25">operator*</a></b> ( qreal <i>factor</i>, const QPoint &amp; <i>point</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator-2b-4">operator+</a></b> ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator-">operator-</a></b> ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator--11">operator-</a></b> ( const QPoint &amp; <i>point</i> )</li>
<li><div class="fn"/>const QPoint <b><a href="qpoint.html#operator-2f">operator/</a></b> ( const QPoint &amp; <i>point</i>, qreal <i>divisor</i> )</li>
<li><div class="fn"/>QDataStream &amp; <b><a href="qpoint.html#operator-lt-lt-43">operator&lt;&lt;</a></b> ( QDataStream &amp; <i>stream</i>, const QPoint &amp; <i>point</i> )</li>
<li><div class="fn"/>bool <b><a href="qpoint.html#operator-eq-eq-22">operator==</a></b> ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</li>
<li><div class="fn"/>QDataStream &amp; <b><a href="qpoint.html#operator-gt-gt-26">operator&gt;&gt;</a></b> ( QDataStream &amp; <i>stream</i>, QPoint &amp; <i>point</i> )</li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QPoint class defines a point in the plane using integer precision.</p>
<p>A point is specified by a x coordinate and an y coordinate which can be accessed using the <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#y">y</a>() functions. The <a href="qpoint.html#isNull">isNull</a>() function returns true if both x and y are set to 0. The coordinates can be set (or altered) using the <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#setY">setY</a>() functions, or alternatively the <a href="qpoint.html#rx">rx</a>() and <a href="qpoint.html#ry">ry</a>() functions which return references to the coordinates (allowing direct manipulation).</p>
<p>Given a point <i>p</i>, the following statements are all equivalent:</p>
<pre> QPoint p;

 p.setX(p.x() + 1);
 p += QPoint(1, 0);
 p.rx()++;</pre>
<p>A QPoint object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A QPoint object can also be divided or multiplied by an <tt>int</tt> or a <tt>qreal</tt>.</p>
<p>In addition, the QPoint class provides the <a href="qpoint.html#manhattanLength">manhattanLength</a>() function which gives an inexpensive approximation of the length of the QPoint object interpreted as a vector. Finally, QPoint objects can be streamed as well as compared.</p>
<p>See also <a href="qpointf.html">QPointF</a> and <a href="qpolygon.html">QPolygon</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QPoint"></a>QPoint::QPoint ()</h3>
<p>Constructs a null point, i.e&#x2e; with coordinates (0, 0)</p>
<p>See also <a href="qpoint.html#isNull">isNull</a>().</p>
<h3 class="fn"><a name="QPoint-2"></a>QPoint::QPoint ( int <i>x</i>, int <i>y</i> )</h3>
<p>Constructs a point with the given coordinates (<i>x</i>, <i>y</i>).</p>
<p>See also <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#setY">setY</a>().</p>
<h3 class="fn"><a name="isNull"></a>bool QPoint::isNull () const</h3>
<p>Returns true if both the x and y coordinates are set to 0, otherwise returns false.</p>
<h3 class="fn"><a name="manhattanLength"></a>int QPoint::manhattanLength () const</h3>
<p>Returns the sum of the absolute values of <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#y">y</a>(), traditionally known as the &quot;Manhattan length&quot; of the vector from the origin to the point. For example:</p>
<pre> QPoint oldPosition;

 MyWidget::mouseMoveEvent(QMouseEvent *event)
 {
     QPoint point = event-&gt;pos() - oldPosition;
     if (point.manhattanLength() &gt; 3)
         <span class="comment">//</span> the mouse has moved more than 3 pixels since the oldPosition
 }</pre>
<p>This is a useful, and quick to calculate, approximation to the true length:</p>
<pre> int trueManhattanLength = sqrt(pow(x(), 2) + pow(y(), 2));</pre>
<p>The tradition of &quot;Manhattan length&quot; arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.</p>
<h3 class="fn"><a name="rx"></a>int &amp; QPoint::rx ()</h3>
<p>Returns a reference to the x coordinate of this point.</p>
<p>Using a reference makes it possible to directly manipulate x. For example:</p>
<pre> QPoint p(1, 2);
 p.rx()--;   <span class="comment">//</span> p becomes (0, 2)</pre>
<p>See also <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#setX">setX</a>().</p>
<h3 class="fn"><a name="ry"></a>int &amp; QPoint::ry ()</h3>
<p>Returns a reference to the y coordinate of this point.</p>
<p>Using a reference makes it possible to directly manipulate y. For example:</p>
<pre> QPoint p(1, 2);
 p.ry()++;   <span class="comment">//</span> p becomes (1, 3)</pre>
<p>See also <a href="qpoint.html#y">y</a>() and <a href="qpoint.html#setY">setY</a>().</p>
<h3 class="fn"><a name="setX"></a>void QPoint::setX ( int <i>x</i> )</h3>
<p>Sets the x coordinate of this point to the given <i>x</i> coordinate.</p>
<p>See also <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#setY">setY</a>().</p>
<h3 class="fn"><a name="setY"></a>void QPoint::setY ( int <i>y</i> )</h3>
<p>Sets the y coordinate of this point to the given <i>y</i> coordinate.</p>
<p>See also <a href="qpoint.html#y">y</a>() and <a href="qpoint.html#setX">setX</a>().</p>
<h3 class="fn"><a name="x"></a>int QPoint::x () const</h3>
<p>Returns the x coordinate of this point.</p>
<p>See also <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#rx">rx</a>().</p>
<h3 class="fn"><a name="y"></a>int QPoint::y () const</h3>
<p>Returns the y coordinate of this point.</p>
<p>See also <a href="qpoint.html#setY">setY</a>() and <a href="qpoint.html#ry">ry</a>().</p>
<h3 class="fn"><a name="operator-2a-eq"></a>QPoint &amp; QPoint::operator*= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3>
<p>Multiplies this point's coordinates by the given <i>factor</i>, and returns a reference to this point. For example:</p>
<pre> QPoint p(-1, 4);
 p *= 2.5;    <span class="comment">//</span> p becomes (-3, 10)</pre>
<p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p>
<p>See also <a href="qpoint.html#operator-2f-eq">operator/=</a>().</p>
<h3 class="fn"><a name="operator-2b-eq"></a>QPoint &amp; QPoint::operator+= ( const QPoint &amp; <i>point</i> )</h3>
<p>Adds the given <i>point</i> to this point and returns a reference to this point. For example:</p>
<pre> QPoint p( 3, 7);
 QPoint q(-1, 4);
 p += q;    <span class="comment">//</span> p becomes (2, 11)</pre>
<p>See also <a href="qpoint.html#operator--eq">operator-=</a>().</p>
<h3 class="fn"><a name="operator--eq"></a>QPoint &amp; QPoint::operator-= ( const QPoint &amp; <i>point</i> )</h3>
<p>Subtracts the given <i>point</i> from this point and returns a reference to this point. For example:</p>
<pre> QPoint p( 3, 7);
 QPoint q(-1, 4);
 p -= q;    <span class="comment">//</span> p becomes (4, 3)</pre>
<p>See also <a href="qpoint.html#operator-2b-eq">operator+=</a>().</p>
<h3 class="fn"><a name="operator-2f-eq"></a>QPoint &amp; QPoint::operator/= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3>
<p>Divides both x and y by the given <i>divisor</i>, and returns a reference to this point. For example:</p>
<pre> QPoint p(-3, 10);
 p /= 2.5;           <span class="comment">//</span> p becomes (-1, 4)</pre>
<p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p>
<p>See also <a href="qpoint.html#operator-2a-eq">operator*=</a>().</p>
<hr />
<h2>Related Non-Members</h2>
<h3 class="fn"><a name="operator-not-eq-13"></a>bool operator!= ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Returns true if <i>p1</i> and <i>p2</i> are not equal; otherwise returns false.</p>
<h3 class="fn"><a name="operator-2a"></a>const QPoint operator* ( const QPoint &amp; <i>point</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3>
<p>Returns a copy of the given <i>point</i> multiplied by the given <i>factor</i>.</p>
<p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p>
<p>See also <a href="qpoint.html#operator-2a-eq">QPoint::operator*=</a>().</p>
<h3 class="fn"><a name="operator-2a-25"></a>const QPoint operator* ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i>, const QPoint &amp; <i>point</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Returns a copy of the given <i>point</i> multiplied by the given <i>factor</i>.</p>
<h3 class="fn"><a name="operator-2b-4"></a>const QPoint operator+ ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Returns a <a href="qpoint.html">QPoint</a> object that is the sum of the given points, <i>p1</i> and <i>p2</i>; each component is added separately.</p>
<p>See also <a href="qpoint.html#operator-2b-eq">QPoint::operator+=</a>().</p>
<h3 class="fn"><a name="operator-"></a>const QPoint operator- ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</h3>
<p>Returns a <a href="qpoint.html">QPoint</a> object that is formed by subtracting <i>p2</i> from <i>p1</i>; each component is subtracted separately.</p>
<p>See also <a href="qpoint.html#operator--eq">QPoint::operator-=</a>().</p>
<h3 class="fn"><a name="operator--11"></a>const QPoint operator- ( const QPoint &amp; <i>point</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Returns a <a href="qpoint.html">QPoint</a> object that is formed by changing the sign of both components of the given <i>point</i>.</p>
<p>Equivalent to <tt>QPoint(0,0) - point</tt>.</p>
<h3 class="fn"><a name="operator-2f"></a>const QPoint operator/ ( const QPoint &amp; <i>point</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3>
<p>Returns the <a href="qpoint.html">QPoint</a> formed by dividing both components of the given <i>point</i> by the given <i>divisor</i>.</p>
<p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p>
<p>See also <a href="qpoint.html#operator-2f-eq">QPoint::operator/=</a>().</p>
<h3 class="fn"><a name="operator-lt-lt-43"></a><a href="qdatastream.html">QDataStream</a> &amp; operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a> &amp; <i>stream</i>, const QPoint &amp; <i>point</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Writes the given <i>point</i> to the given <i>stream</i> and returns a reference to the stream.</p>
<p>See also <a href="datastreamformat.html">Format of the QDataStream Operators</a>.</p>
<h3 class="fn"><a name="operator-eq-eq-22"></a>bool operator== ( const QPoint &amp; <i>p1</i>, const QPoint &amp; <i>p2</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Returns true if <i>p1</i> and <i>p2</i> are equal; otherwise returns false.</p>
<h3 class="fn"><a name="operator-gt-gt-26"></a><a href="qdatastream.html">QDataStream</a> &amp; operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a> &amp; <i>stream</i>, QPoint &amp; <i>point</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Reads a point from the given <i>stream</i> into the given <i>point</i> and returns a reference to the stream.</p>
<p>See also <a href="datastreamformat.html">Format of the QDataStream Operators</a>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
